#include "BusinessThread.h"
#include <QDebug>

BusinessThread::BusinessThread(QObject *parent) : QThread(parent)
{
    kithara_user_ = new KitharaUser(this);
    connect(kithara_user_,&KitharaUser::SendData,this,&BusinessThread::SendData);
}

BusinessThread::~BusinessThread() = default;

void BusinessThread::Stop() const
{
    kithara_user_->Stop();
}

QStringList BusinessThread::GetNetworkList() const
{
   return kithara_user_->GetNetworkList();
}

void BusinessThread::SetNetworkIndex(int index)
{
    kithara_user_->SetNetworkIndex(index);
}

void BusinessThread::run()
{
    if (kithara_user_ == nullptr)
    {
        emit OperationResult(-1,"kithara_user_ is nullptr");
        return;
    }

    bool ret = kithara_user_->Init();
    if (!ret)
    {
        emit OperationResult(-1,"kithara_user_->Init() failed");
        return;
    }

    ret = kithara_user_->Start();
    if (!ret)
    {
        emit OperationResult(-1,"kithara_user_->Start() failed");
        return;
    }

    emit OperationResult(0 , "Server Start Success!");

    kithara_user_->WaitForStop();

    kithara_user_->UnInit();
    emit OperationResult(0 , "Server Close Success!");
}
